/**
 * Created by zhout3517 on 2017-6-7.
 * 控制表格过滤行显示/隐藏 ng指令
 */
shared.directive('fFilterBtn', function ($http, $templateCache) {
    return {
        restrict: 'E',
        template: $templateCache.get('filter.html'),
        scope: {
            gridFor: '@'
        },
        replace: true,
        link: function (scope, element, attrs) {
            //国际化
            scope.i18n = I18N.FILTER;
            // 过滤行控制按钮点击事件
            scope.filterBtnClkEvt = function (ele) {
                var gridElement = ele||angular.element('#' + scope.gridFor);
                var filterRowShow = gridElement.hasClass('filterRow');

                var newHeight = gridElement.innerHeight();
                var otherElements = gridElement.children().not('.k-grid-content');
                //61表示过滤行height为61px，当过滤行css改变时该数值可能也需要改变
                var otherElementsHeight = filterRowShow ? -61 : 61;

                otherElements.each(function () {
                    otherElementsHeight += $(this).outerHeight();
                });
                gridElement[filterRowShow ? 'removeClass' : 'addClass']('filterRow');
                gridElement.children('.k-grid-content').height(newHeight - otherElementsHeight);
            };
        }
    };
});
